import {reqGoodsInfo,reqAddOrUpdateShopCart} from "@/api"
import {getUUID} from "@/utils/uuid_token.js"

const state= {
  goodInfo:{},
  uuid_token:getUUID() 
}
const mutations= {
  GETGOODINFO(state,res){
    state.goodInfo = res
  }
}
const  actions = {  
async getGoodsInfo({commit},skuId){
  let  result   = await  reqGoodsInfo(skuId)
  if(result.code==200) commit("GETGOODINFO",result.data)
  },
  //添加到购物车中
 async addOrUpdateShopCart({commit},{skuId,num}){
    let result =  await reqAddOrUpdateShopCart(skuId,num)
   return result
  }
}
const getters={
  categoryView(state){
    return state.goodInfo.categoryView||{}
  },
  skuInfo(state){
    return state.goodInfo.skuInfo||{}
  },
  spuSaleAttrList(state){
    return   state.goodInfo.spuSaleAttrList ||[]
  }
}



export default{
  namespaced: true,
  state,
  actions,
mutations,
  getters

}